﻿using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Data.Entity.ModelConfiguration;
using sharp_net.Repositories;
using zkdao.Enum;
using sharp_net.Repositories;

namespace zkdao.Domain {

    public class Image : DomainInt, IAggregateRoot {

        [Required]
        public string Path { get; set; }

        public Guid PosterID { get; set; }

        public string HostID { get; set; }

        public int HostTypeEnum { get; set; }
        public eImageHostType HostType {
            get { return (eImageHostType)HostTypeEnum; }
            set { HostTypeEnum = (int)value; }
        }

        public void Update(ImageData data) {
            if (!string.IsNullOrEmpty(data.Path))
                this.Path = data.Path;
            if (!string.IsNullOrEmpty(data.HostID)) {
                Guid host_guid;
                int host_id;
                if (Guid.TryParse(data.HostID, out host_guid)) {
                    this.HostID = host_guid.ToString();
                } else if (int.TryParse(data.HostID, out host_id)) {
                    this.HostID = host_id.ToString();
                }
            }
            if (data.ActEnum != 0)
                this.ActEnum = data.ActEnum;
        }
    }

    public class ImageData : DomainIntData {

        public string Path { get; set; }

        public string PosterID { get; set; }

        public string HostID { get; set; }

        public int HostTypeEnum { get; set; }
    }

}